package com.jinunn.hosp.controller;

import com.atguigu.yygh.model.hosp.Hospital;
import com.atguigu.yygh.model.hosp.Schedule;
import com.atguigu.yygh.vo.hosp.DepartmentVo;
import com.atguigu.yygh.vo.hosp.HospitalQueryVo;
import com.jinunn.common.result.Result;
import com.jinunn.hosp.service.DepartmentService;
import com.jinunn.hosp.service.HospitalService;
import com.jinunn.hosp.service.ScheduleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author JinDnn
 * @date 2021/5/1 0:11
 */

@RestController
@RequestMapping("/admin/hosp")
public class HospitailController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation("医院列表")
    @GetMapping("list/{page}/{limit}")
    public Result<Page<Hospital>> list(@PathVariable("page") Integer page,
                                       @PathVariable("limit") Integer limit,
                                       HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitalList =hospitalService.seleteHospPage(page,limit,hospitalQueryVo);
        return Result.ok(hospitalList);
    }

    @ApiOperation(value = "更新医院上线状态")
    @GetMapping("updateHospStatus/{id}/{status}")
    public Result<Hospital> updateHospStatus(@PathVariable("id") String id,
                                   @PathVariable("status") Integer status){
        hospitalService.updateHospStatus(id,status);
        return Result.ok();
    }

    @ApiOperation(value = "医院详情信息")
    @GetMapping("detail/{id}")
    public Result<Map<String,Object>> showDetail(@PathVariable("id") String id){
        Map<String,Object> map = hospitalService.showDetail(id);
        return Result.ok(map);
    }

    @ApiOperation("根据医院编号获取科室")
    @GetMapping("department/{hoscode}")
    public Result<List<DepartmentVo>> getDepartment(@PathVariable("hoscode") String hoscode){
        List<DepartmentVo> deptTree = departmentService.getDeptTree(hoscode);
        return Result.ok(deptTree);
    }

    @ApiOperation("根据医院编号获取挂号详情")
    @GetMapping("registeredDetail/{hoscode}")
    public Result<Map<String,Object>> registeredDetail(@PathVariable("hoscode") String hoscode){
        Map<String,Object> map = hospitalService.getRegisteredDetail(hoscode);
        return Result.ok(map);
    }

    @ApiOperation("获取可预约排班数据")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result<Map<String,Object>> getBookingScheduleRule(@PathVariable("page") Integer page,
                                         @PathVariable("limit") Integer limit,
                                         @PathVariable("hoscode") String hoscode,
                                         @PathVariable("depcode") String depcode){
        Map<String,Object> map = scheduleService.getBookingScheduleRule(page,limit,hoscode,depcode);
        return Result.ok(map);
    }

    @ApiOperation("获取排版数据")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result<List<Schedule>> findScheduleList(@PathVariable("hoscode") String hoscode,
                                   @PathVariable("depcode") String depcode,
                                   @PathVariable("workDate") String workDate){
        List<Schedule> scheduleDetail = scheduleService.getScheduleDetail(hoscode, depcode, workDate);
        return Result.ok(scheduleDetail);
    }
}
